<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "mkt_source_gift".
 *
 * @property string $id
 * @property string $user_id
 * @property string $gift_type
 * @property string $gift_count
 * @property string $gift_price
 */
class MktSourceGift extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mkt_source_gift';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'gift_type', 'gift_count', 'gift_price'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户编号',
            'gift_type' => '礼品类型',      // 实物礼品，电子券，纸质券，购物卡，门票
            'gift_count' => '礼品数量',
            'gift_price' => '礼品单价',
        ];
    }

    /**
     * @inheritdoc
     * @return MktSourceGiftQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new MktSourceGiftQuery(get_called_class());
    }

    public function getUser()
    {
        return $this->hasOne(MktUser::className(), ['id' => 'user_id']);
    }

    static function getGiftTypeOption($key=null)
    {
        $arr = array(
            1 => '实物礼品',
            2 => '电子券',
            3 => '纸质券',
            4 => '购物卡',
            5 => '门票',
        );        
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }
    

    
}
